import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/',
    component: () => import('@/views/login/login'),
    hidden:true
  },

  {
    path: '/tenantRegister',
    component: () => import('@/views/sysManage/tenantRegister'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/home',
    component: Layout,
    children: [{
      path: '',
      name: '首页',
      component: () => import('@/views/home/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  {
    path: '/sys',
    component: Layout,
    redirect: '/sys/tenantType',
    name: '系统中心',
    meta: { title: '系统中心', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'tenantType',
        name: '租户类型',
        component: () => import('@/views/sysManage/tenantType'),
        meta: { title: '租户类型', icon: 'table' }
      },
      {
        path: 'tenantManage',
        name: '租户列表',
        component: () => import('@/views/sysManage/tenantManage'),
        meta: { title: '租户列表', icon: 'tree' }
      },
      {
        path: 'mealManage',
        name: '套餐列表',
        component: () => import('@/views/sysManage/mealManage'),
        meta: { title: '套餐列表', icon: 'tree' }
      },
      {
        path: 'depManage',
        name: '部门列表',
        component: () => import('@/views/sysManage/depManage'),
        meta: { title: '部门列表', icon: 'tree' }
      },
      {
        path: 'empManage',
        name: '员工列表',
        component: () => import('@/views/sysManage/empManage'),
        meta: { title: '员工列表', icon: 'tree' }
      },
      {
        path: 'configManage',
        name: '系统配置',
        component: () => import('@/views/sysManage/configManage'),
        meta: { title: '系统配置', icon: 'tree' }
      },
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/userList',
    name: '用户中心',
    meta: { title: '用户中心', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'userList',
        name: '用户列表',
        component: () => import('@/views/user/userList'),
        meta: { title: '用户列表', icon: 'table' }
      },
      {
        path: 'userAddress',
        name: '用户地址',
        component: () => import('@/views/user/userAddress'),
        meta: { title: '用户地址', icon: 'table' }
      },
      {
        path: 'userGrowLog',
        name: '成长记录',
        component: () => import('@/views/user/userGrowLog'),
        meta: { title: '成长记录', icon: 'table' }
      },
      {
        path: 'userRealLog',
        name: '实名认证',
        component: () => import('@/views/user/userRealLog'),
        meta: { title: '实名认证', icon: 'table' }
      }
    ]
  },


  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
